﻿@page "/{year}/{month}/{slug}"
@page "/post/{year}/{month}/{slug}"
@page "/bbs/post/{year}/{month}/{slug}"

@inherits BaseComponent
@inject AppService AppService
@inject IOptions<SiteOption> SiteOption

<PageTitle>@model?.Title - @SiteOption.Value.AppTitle</PageTitle>

<div class="container cl-container cl-post">
    <div id="@mdId">
        <div id="toc">
            <div >
                <a class="item-title" href="@GetTopLink()" title="@model?.Title">@model?.Title</a>
            </div>
        </div>
        <CmsCard>
            <HeadTemplate>
                <CmsTitle Icon="far fa-file" Title="@model?.Title"/>
                <UPostCount Post="model"/>
            </HeadTemplate>
            <ChildContent>
                @if (!string.IsNullOrWhiteSpace(model?.HtmlContent))
                {
                    @((MarkupString)model.HtmlContent)
                }
                <div class="button">
                    <a href="@ConstantUtil.GetPostGithubPath(SiteOption.Value.RemoteAssetsRepository, model)" target="_blank">在Github上编辑此文或留言</a>
                </div>
            </ChildContent>
        </CmsCard>
        <div style="height:20px;"></div>
    </div>
    <div>
        <UWebSiteCount/>
        <div style="height: 20px;"></div>
        <UPostRank/>
    </div>
</div>

<script>
    $(getTOC('@mdId'));
</script>

@code {
    Guid mdId = Guid.NewGuid();
    string GetTopLink() => Navigation.GetPageUrl().Split('#')[0] + '#' + mdId;
    private BlogPost? model;

    [Parameter] public string? Year { get; set; }
    [Parameter] public string? Month { get; set; }
    [Parameter] public string Slug { get; set; }

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();

        model = await AppService.GetPostBySlug(Slug);
    }

}